<html>
<head><meta charset="utf-8"><title>code:goto impl BarT for . :: bar, not trait BarT::bar · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html">code:goto impl BarT for . :: bar, not trait BarT::bar</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197078963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/code%3Agoto%20impl%20BarT%20for%20.%20%3A%3A%20bar%2C%20not%20trait%20BarT%3A%3Abar/near/197078963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html#197078963">(May 10 2020 at 21:14)</a>:</h4>
<p>Suppose we have:</p>
<div class="codehilite"><pre><span></span><code>trait BarT {
  fn bar(&amp;self) ;
}

impl BarT for Dog { ... };

fn main() {
  let dog: Dog;
  dog.bar();
}
</code></pre></div>


<p>now, suppose the cursor is over the bar of <code>dog.bar</code>. At this point, when I try to go to reference, I get thrown to the 'BarT::bar'. However, since the compiler knows that <code>dog: Dog</code>, is there a way to have it jump to <code>impl BarT for Dog::bar</code> ?</p>
<p>I.e. in situations where the compiler knows the type of the lhs of the <code>.bar</code>, I want it to jump me to the right <code>impl</code>, rather than the generic <code>trait BarT</code></p>
<p>This works for me in IntelliJ/Rust most of the time, but I can't figure out how to do this in vs code.</p>



<a name="197079045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/code%3Agoto%20impl%20BarT%20for%20.%20%3A%3A%20bar%2C%20not%20trait%20BarT%3A%3Abar/near/197079045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html#197079045">(May 10 2020 at 21:15)</a>:</h4>
<p>(I'm using latest vs code, latest rust analyzer, and rustc nightly)</p>



<a name="197104967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/code%3Agoto%20impl%20BarT%20for%20.%20%3A%3A%20bar%2C%20not%20trait%20BarT%3A%3Abar/near/197104967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html#197104967">(May 11 2020 at 06:35)</a>:</h4>
<p>Not right now, but it might be possible to offer it because once you're on the trait method, you can choose "Go to Implementations" and it will highlight the <code>Dog</code> one. Maybe "Go to Definition" should take you to the implementation, though I'm not sure it makes sense.</p>



<a name="197144319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/code%3Agoto%20impl%20BarT%20for%20.%20%3A%3A%20bar%2C%20not%20trait%20BarT%3A%3Abar/near/197144319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html#197144319">(May 11 2020 at 13:23)</a>:</h4>
<p>I don't know if we are talking the same thing. If I put the cursor over <code>BarT::bar</code>, and hit ctrl-t, it will show me ALL implementations and I can choose. The downside is  that if Dog, Cat, Rat, Donkey, Eagle, ... all implement the trait, then I have to manually pick the one.</p>



<a name="197144779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/code%3Agoto%20impl%20BarT%20for%20.%20%3A%3A%20bar%2C%20not%20trait%20BarT%3A%3Abar/near/197144779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html#197144779">(May 11 2020 at 13:27)</a>:</h4>
<p>It's not the same thing, but since it finds the <code>Dog</code> implementation, it could presumably navigate there</p>



<a name="197146760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/code%3Agoto%20impl%20BarT%20for%20.%20%3A%3A%20bar%2C%20not%20trait%20BarT%3A%3Abar/near/197146760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/code.3Agoto.20impl.20BarT.20for.20.2E.20.3A.3A.20bar.2C.20not.20trait.20BarT.3A.3Abar.html#197146760">(May 11 2020 at 13:43)</a>:</h4>
<p>Sure, but the problem is the mental cost of doing "what is the type of this var" so I can select the right one, whereas I'd really prefer the compiler/IDE just did this for me.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>